package com.esbi.projectwebsocket.collect.toJson;
import com.alibaba.fastjson.JSON;
import com.google.gson.Gson;

public class JsonExample {
    public static void main(String[] args) {
        Person person = new Person("John", 30);
        System.out.println(person);
        String jsonString = JSON.toJSONString(person);//将java对象转换为字符串
        System.out.println(jsonString);//输出json对象
        /**
         * 下面写将json字符串转换为java对象
         */
        Person person1 = JSON.parseObject(jsonString, Person.class);
        System.out.print("\33[44;1m"+person1+"\n\33[0m");//紫色背景
    }


}